/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "service")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Service.findAll", query = "SELECT s FROM Service s"),
    @NamedQuery(name = "Service.findById", query = "SELECT s FROM Service s WHERE s.id = :id"),
    @NamedQuery(name = "Service.findByName", query = "SELECT s FROM Service s WHERE s.name = :name"),
    @NamedQuery(name = "Service.findByLoc", query = "SELECT s FROM Service s WHERE s.loc = :loc"),
    @NamedQuery(name = "Service.findByMinCPU", query = "SELECT s FROM Service s WHERE s.minCPU = :minCPU"),
    @NamedQuery(name = "Service.findByMaxCPU", query = "SELECT s FROM Service s WHERE s.maxCPU = :maxCPU"),
    @NamedQuery(name = "Service.findByMinMEM", query = "SELECT s FROM Service s WHERE s.minMEM = :minMEM"),
    @NamedQuery(name = "Service.findByMaxMEM", query = "SELECT s FROM Service s WHERE s.maxMEM = :maxMEM"),
    @NamedQuery(name = "Service.findByMinStorage", query = "SELECT s FROM Service s WHERE s.minStorage = :minStorage"),
    @NamedQuery(name = "Service.findByMaxStorage", query = "SELECT s FROM Service s WHERE s.maxStorage = :maxStorage")})
public class Service implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private String id;
    @Column(name = "Name")
    private String name;
    @Column(name = "LOC")
    private BigInteger loc;
    @Column(name = "minCPU")
    private Long minCPU;
    @Column(name = "maxCPU")
    private Long maxCPU;
    @Column(name = "minMEM")
    private Long minMEM;
    @Column(name = "maxMEM")
    private Long maxMEM;
    @Column(name = "minStorage")
    private Long minStorage;
    @Column(name = "maxStorage")
    private Long maxStorage;
    @JoinTable(name = "service_requirements", joinColumns = {
        @JoinColumn(name = "Id_Required", referencedColumnName = "ID")}, inverseJoinColumns = {
        @JoinColumn(name = "Id_Requires", referencedColumnName = "ID")})
    @ManyToMany
    private Collection<Service> serviceCollection;
    @ManyToMany(mappedBy = "serviceCollection")
    private Collection<Service> serviceCollection1;
    @ManyToMany(mappedBy = "serviceCollection")
    private Collection<Activity> activityCollection;
    @JoinTable(name = "service_vm_conf", joinColumns = {
        @JoinColumn(name = "Id_Service", referencedColumnName = "ID")}, inverseJoinColumns = {
        @JoinColumn(name = "Id_VirtualMachineConf", referencedColumnName = "ID")})
    @ManyToMany
    private Collection<VirtualMachineConf> virtualMachineConfCollection;
    @OneToMany(mappedBy = "idService")
    private Collection<ServiceInstance> serviceInstanceCollection;
    @JoinColumn(name = "ID", referencedColumnName = "ID", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Component component;

    public Service() {
    }

    public Service(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigInteger getLoc() {
        return loc;
    }

    public void setLoc(BigInteger loc) {
        this.loc = loc;
    }

    public Long getMinCPU() {
        return minCPU;
    }

    public void setMinCPU(Long minCPU) {
        this.minCPU = minCPU;
    }

    public Long getMaxCPU() {
        return maxCPU;
    }

    public void setMaxCPU(Long maxCPU) {
        this.maxCPU = maxCPU;
    }

    public Long getMinMEM() {
        return minMEM;
    }

    public void setMinMEM(Long minMEM) {
        this.minMEM = minMEM;
    }

    public Long getMaxMEM() {
        return maxMEM;
    }

    public void setMaxMEM(Long maxMEM) {
        this.maxMEM = maxMEM;
    }

    public Long getMinStorage() {
        return minStorage;
    }

    public void setMinStorage(Long minStorage) {
        this.minStorage = minStorage;
    }

    public Long getMaxStorage() {
        return maxStorage;
    }

    public void setMaxStorage(Long maxStorage) {
        this.maxStorage = maxStorage;
    }

    @XmlTransient
    public Collection<Service> getServiceCollection() {
        return serviceCollection;
    }

    public void setServiceCollection(Collection<Service> serviceCollection) {
        this.serviceCollection = serviceCollection;
    }

    @XmlTransient
    public Collection<Service> getServiceCollection1() {
        return serviceCollection1;
    }

    public void setServiceCollection1(Collection<Service> serviceCollection1) {
        this.serviceCollection1 = serviceCollection1;
    }

    @XmlTransient
    public Collection<Activity> getActivityCollection() {
        return activityCollection;
    }

    public void setActivityCollection(Collection<Activity> activityCollection) {
        this.activityCollection = activityCollection;
    }

    @XmlTransient
    public Collection<VirtualMachineConf> getVirtualMachineConfCollection() {
        return virtualMachineConfCollection;
    }

    public void setVirtualMachineConfCollection(Collection<VirtualMachineConf> virtualMachineConfCollection) {
        this.virtualMachineConfCollection = virtualMachineConfCollection;
    }

    @XmlTransient
    public Collection<ServiceInstance> getServiceInstanceCollection() {
        return serviceInstanceCollection;
    }

    public void setServiceInstanceCollection(Collection<ServiceInstance> serviceInstanceCollection) {
        this.serviceInstanceCollection = serviceInstanceCollection;
    }

    public Component getComponent() {
        return component;
    }

    public void setComponent(Component component) {
        this.component = component;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Service)) {
            return false;
        }
        Service other = (Service) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.Service[ id=" + id + " ]";
    }
    
}
